package com.tao.utilslib.log.logsave.task;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

public class AddEndSaveTask extends BaseAddTask {
    String log;
    String path;

    public AddEndSaveTask(String log, String path) {
        this.log = log;
        this.path = path;
    }

    @Override
    public void run() {
        addLog(path, appendLogHead(log));
    }

    public void addLog(String path, String log) {
        BufferedWriter writer = null;
        FileOutputStream fileOutputStream=null;
        OutputStreamWriter out=null;
        try {
              fileOutputStream = new FileOutputStream(path, true);
              out = new OutputStreamWriter(fileOutputStream);
            writer = new BufferedWriter(out);
            writer.write("\n");
            writer.write(log, 0, log.length());
        } catch ( Exception e) {
            e.printStackTrace();
        } finally {
            closeIo(writer);
            closeIo(fileOutputStream);
            closeIo(out);
        }
    }

}
